// pages/collect/index.js
Page({
  data: {
    // tabs栏的数据数组
    tabs: [{
      id: 0,
      name: "商品收藏",
      isActive: true
    }, {
      id: 1,
      name: "品牌收藏",
      isActive: false
    }, {
      id: 2,
      name: "店铺收藏",
      isActive: false
    }, {
      id: 3,
      name: "浏览足迹",
      isActive: false
    }],
    // 已经收藏的商品列表
    collect: []
  },
  onShow() {
    // 从缓存中拿到商品收藏数组collect
    const collect = wx.getStorageSync("collect") || []
    // 保存到data中
    this.setData({
      collect
    })
  },
  // tabs栏位切换事件 从子组件传递值过来
  bindReceiveIndex(e) {
    const index = e.detail
    const tabs = this.data.tabs
    tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false)
    this.setData({
      tabs
    })
  }
})